package com.crm.controller;

import com.crm.annotation.LogOperation;
import com.crm.dto.ActivityDto;
import com.crm.entity.Activity;
import com.crm.result.ActivityResult;
import com.crm.result.AjaxResult;
import com.crm.result.PageResult;
import com.crm.result.Result;
import com.crm.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/clues/activity")
@Slf4j
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    //活动分页查询
    @LogOperation(title = "活动管理")
    @GetMapping("/list")
    public ActivityResult pageActivities(ActivityDto activityDto){
        PageResult res = activityService.getActivityPageWithConditions(activityDto);
        return ActivityResult.success("查询成功", null, res.getRows(), res.getTotal());
    }

    //新增活动
    @PostMapping
    public Result addActivity(@RequestBody ActivityDto activityDto){
        log.info("新增活动：{}",activityDto.getName());
        activityService.add(activityDto);
        return Result.success();
    }

    //删除活动
    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable("id") Long id){
        log.info("删除活动：{}",id);
        activityService.delete(id);
        return Result.success();
    }

    //根据ID查询活动详细
    @GetMapping("/{id}")
    public Result<Activity> selectById(@PathVariable("id") Integer id){
        log.info("根据ID查询活动：{}",id);
        Activity activity = activityService.selectById(id);
        return Result.success(activity);
    }

    //修改活动信息
    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        log.info("修改活动：{}",activity.getName());
        activityService.update(activity);
        return Result.success();
    }
    //根据活动类型监听活动信息,列表查询
    @GetMapping("/listselect/{channelId}")
    public Result<List<Activity>> list(@PathVariable Long channelId){
        List<Activity> activities = activityService.selectAll(channelId);
        return Result.success(activities);
    }

}
